package com.yx.fx.webApi.serviceImpl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yx.fx.common.model.response.Outcome;
import com.yx.fx.sys.web.business.SysUserBusiness;
import com.yx.fx.sys.web.business.SysUtilBusiness;
import com.yx.fx.sys.web.model.UserInfo;
import com.yx.fx.webApi.entity.BankAccessInfo;
import com.yx.fx.webApi.mapper.BankAccessInfoMapper;
import com.yx.fx.webApi.param.BankAccessInfoParam;
import com.yx.fx.webApi.service.BankAccessInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.HashMap;
import java.util.List;
import java.util.Set;


/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author pxb
 * @since 2021-09-17
 */
@Service("bankAccessInfoServiceImpl")
public class BankAccessInfoServiceImpl extends ServiceImpl<BankAccessInfoMapper, BankAccessInfo> implements BankAccessInfoService {

    @Resource
    private BankAccessInfoService bankAccessInfoService;

    @Resource
    private SysUserBusiness sysUserBusiness;

    @Autowired
    SysUtilBusiness sysUtilBusiness;

    @Autowired
    BankAccessInfoMapper bankAccessInfoMapper;

    /**
     * 提交结果
     * 已存在-->更新
     * 不存在-->添加
     *
     * @param param 角色数据
     * @return 是否成功
     */
    public Outcome saveOrUpdate(BankAccessInfoParam param) {
        UserInfo userInfo = sysUserBusiness.getUserInfo();
        BankAccessInfo bankAccessInfo = Convert.convert(BankAccessInfo.class, param);
        return Outcome.status(bankAccessInfoService.saveOrUpdate(bankAccessInfo));
    }


    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public boolean delete(List<Long> id) {
        return bankAccessInfoService.delete(id);
    }

    /**
     * 查询
     *
     * @param param
     * @return
     */
    @Override
    public IPage getBankAccessInfoList(BankAccessInfoParam param) {
        // 数据权限
        Set<Long> dataScope = sysUtilBusiness.getDataScope();
        HashMap<Object, Object> map = new HashMap<>();
        System.out.println(param);
        map.put("id", param.getId());
        return bankAccessInfoMapper.getBankAccessInfoList(new Page<>(param.pageNum, param.pageSize), map);
    }

}

